//package com.rbac.web.mq.producer;
//
//import com.google.gson.Gson;
//import com.rbac.web.model.User;
//import com.rbac.web.model.res.UserGetOneRes;
//import com.rbac.web.service.ISysParamCodeService;
//import com.rbac.web.service.IUserService;
//import io.swagger.v3.oas.annotations.tags.Tag;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.client.producer.SendCallback;
//import org.apache.rocketmq.client.producer.SendResult;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
///**
// * @author gengaoliu
// */
//@RestController
//@RequestMapping("/user_produce")
//@Slf4j
//@Tag(name = "生产用户消息", description = "刘澳港")
//public class UserProducer {
//
//  private static final String DEFAULT_TOPIC = "send-user-msg";
//  @Autowired
//  private RocketMQTemplate rocketMQTemplate;
//  @Autowired
//  private IUserService userService;
//  @Autowired
//  private ISysParamCodeService sysParamCodeService;
//  private final Gson gson;
//
//  public UserProducer(Gson gson) {
//    this.gson = gson;
//  }
//
//  /**
//   * 效率较高，消息发送至rocketmq之后，有回调函数，成功或者失败，建议使用这个方法
//   * @param userId userId
//   * @return User的返回信息
//   */
//  @GetMapping("/create/{userId}")
//  public UserGetOneRes createUser(@PathVariable("userId") Integer userId) {
//    String redisConf = sysParamCodeService.getRedisConf("test", "test", "test");
//    log.info("SysParamCode为：{}", redisConf);
//    User user = userService.findById(userId);
//    user.setSysDesc(redisConf);
//    log.info("User为:{}", user);
//    UserGetOneRes userGetOneRes = UserGetOneRes.from(user);
//    rocketMQTemplate.asyncSend(DEFAULT_TOPIC,
//        MessageBuilder.withPayload(gson.toJson(userGetOneRes)).build(),
//        new SendCallback() {
//          @Override
//          public void onSuccess(SendResult sendResult) {
//            log.info("User:{},发送成功", userGetOneRes.getName());
//          }
//
//          @Override
//          public void onException(Throwable e) {
//            log.info("User:{},发送失败", userGetOneRes.getName());
//          }
//        });
//    return userGetOneRes;
//  }
//}
